package mybatis.web;
import mybatis.pojo.Grade;
import mybatis.pojo.Page;
import mybatis.services.GradeService;
import mybatis.util.StrUtil;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @Author 汤舒青
 * @Version 1.0
 */

@WebServlet("/grade")
public class GradeServlet  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        this.doGet(req,resp);
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.setCharacterEncoding("utf-8");
        String gname = req.getParameter("gname");
        gname = gname == null ? "" : gname;
        int pageNo = StrUtil.toInt(req.getParameter("pageNo"), 1);
        //List<Grade> all = GradeService.ME.findAll();
        Page<Grade> p = GradeService.ME.showGrade(pageNo, gname);
        req.setAttribute("page",p);
        req.setAttribute("pageNo",pageNo);
        req.setAttribute("gname",gname);
        //req.setAttribute("grades",all);
        req.getRequestDispatcher("/grade.jsp").forward(req,resp);
    }
}